//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.imagemanager.util;

import java.util.ArrayList;
import java.util.Arrays;

public final class ArrayUtils {
    public ArrayUtils() {
    }

    public static final void computeSortedIntersection(ArrayList<MediaItem> firstList, ArrayList<MediaItem> secondList, int maxSize, ArrayList<MediaItem> intersectionList, MediaItem[] hash) {
        int mask = hash.length - 1;
        int numItemsToHash = Math.min(secondList.size(), 2 * hash.length);

        int firstListSize;
        for(firstListSize = 0; firstListSize < numItemsToHash; ++firstListSize) {
            MediaItem item = (MediaItem)secondList.get(firstListSize);
            if(item != null) {
                hash[item.hashCode() & mask] = item;
            }
        }

        firstListSize = firstList.size();

        for(int i = 0; i < firstListSize; ++i) {
            MediaItem firstListItem = (MediaItem)firstList.get(i);
            if(firstListItem != null) {
                MediaItem hashItem = hash != null?hash[firstListItem.hashCode() & mask]:null;
                if(hashItem != null && (hashItem.mId != -1L && hashItem.mId == firstListItem.mId || contains(secondList, firstListItem))) {
                    intersectionList.add(firstListItem);
                    --maxSize;
                    if(maxSize == 0) {
                        break;
                    }
                }
            }
        }

        Arrays.fill(hash, (Object)null);
    }

    public static final boolean contains(Object[] array, Object object) {
        if(object == null) {
            return false;
        } else {
            int length = array.length;

            for(int i = 0; i < length; ++i) {
                if(object.equals(array[i])) {
                    return true;
                }
            }

            return false;
        }
    }

    public static void clear(Object[] array) {
        int length = array.length;

        for(int i = 0; i < length; ++i) {
            array[i] = null;
        }

    }

    public static final boolean contains(ArrayList<MediaItem> items, MediaItem item) {
        int numItems = items.size();
        if(item.mId == -1L) {
            return false;
        } else {
            for(int i = 0; i < numItems; ++i) {
                MediaItem thisItem = (MediaItem)items.get(i);
                if(item.mId == thisItem.mId) {
                    return true;
                }
            }

            return false;
        }
    }
}
